<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function test(nums, k) {
            if (nums.length === 1) return nums[0] === k ? 1 : 0
            let count = 0
            let sum = 0
            for (let j = 0; j < nums.length; j++) {
                for (let i = j; i < nums.length; i++) {
                    sum += nums[i]
                    if (sum === k) {
                        count++
                        sum = 0
                        break
                    } else if (sum > k) {
                        sum = 0
                        break
                    }
                }
            }
            return count
        }

        console.log(test([1, 2, 3], 3));
    </script>
</body>

</html>